package com.marvels.system.common.component;

import java.util.List;
import java.util.Map;

import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import com.marvels.common.utils.CacheUtils;
import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.system.common.dao.SysMenuDao;
import com.marvels.system.common.dto.SysMenuDTO;

@Component
public class MarvelsApplicationRunner implements ApplicationRunner {

	@Autowired
	SysMenuDao sysMenuDao;
	
	@Override
	public void run(ApplicationArguments args) throws Exception {
		MarvelsLogUtil.getInstance().info("开始初始化权限信息");
		List<SysMenuDTO> menuList = sysMenuDao.selectAllPermission();
		Map<String,String> needPermissionMap = new HashedMap();
		for(SysMenuDTO sysMenuDTO : menuList) {
			needPermissionMap.put(sysMenuDTO.getMenuUrl(), sysMenuDTO.getMenuUrl());
			MarvelsLogUtil.getInstance().info("初始化权限信息"+sysMenuDTO.getMenuUrl());
		}
		MarvelsLogUtil.getInstance().info("结束初始化权限信息");
		CacheUtils.cacheObject("needPermissionMap", needPermissionMap);
	}

}
